<?php

//This is the file I gave you earlier with the database connection script and stuff.
require_once("overhead.php");

class Professor {

	var $ID; //corresponds to the Primary key in the department table (also called ID)
	var $lastName; //Corresponds to the professor's last name
	var $firstName; //Correspsonds to the professor's first name	
	

	//Getters and setters don't directly touch the database.
	public function getID() {
		return $this->ID;
	}
	public function getLastName() {
		return $this->lastName;
	}
	public function getFirstName() {
		return $this->firstName;
	}
	public function setLastName($ln) {
		$this->lastName=$ln;
	}
	public function setFirstName($fn) {
		$this->firstName=$fn;
	}
	
	public function getNeatName()    {
	return $this->getLastName().", ".$this->getFirstName();
	}
	
	public function retrieveFromID($idn) {
		$queryString="select ID, FirstName, LastName from Professor where Professor.ID=".$idn;
		$query=mysql_query($queryString);
		$result=mysql_fetch_assoc($query);
		 if ($result) {
		 	//If something was found, put all the fields from the database (in $result right now) into
		 	//the instance variables for this object.
 			$this->ID=$result['ID'];
 			$this->lastName=$result['LastName'];
 			$this->firstName=$result['FirstName'];
 			//return true because we found it!
 			return true;
 		} else {
 			//it wasn't found or there was an error, so return false.
 			return false;
 		}
	}
	public function update() {
	$queryString="UPDATE Professor SET LastName='".$this->lastName."', FirstName='".$this->firstName."' WHERE ID=".$this->ID;
	$query=mysql_query($queryString);
	if ($queryString){
		return true;}
	else {
	return false;
	}}
	
  	public function insert() {
  	$queryString="INSERT INTO Professor (FirstName, LastName) VALUES ('".$this->firstName."', '".$this->lastName."')";
  	$query=mysql_query($queryString);
  	if ($query) {
		$getIDQueryString="select LAST_INSERT_ID() as NewID";
		$getIDQuery=mysql_query($getIDQueryString);
		$result=mysql_fetch_assoc($getIDQuery);
		if ($result) {
			$this->ID=$result['NewID'];
			return true;
		} else { return false; }
	} else {
		return false;
	}
}
	
	public function delete() {
	$queryString="DELETE FROM Professor WHERE ID=".$this->ID;
	$query=mySQL_query($queryString);
	if ($queryString){
		return true;}
	else {
	return false;
	}}
	}